package com.app.bussinesslocator.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

import com.app.bussinesslocator.R;
import com.app.bussinesslocator.Utils.IOUtils;
import com.app.bussinesslocator.adapter.ResultAdapter.Holder;
import com.app.bussinesslocator.bean.ObjOpenHours;

public class ListOpenHourAdapter extends ArrayAdapter<ObjOpenHours> {

	Context context;
	ArrayList<ObjOpenHours> objOpenHours;

	public ListOpenHourAdapter(Context context,
			ArrayList<ObjOpenHours> objOpenHours) {
		super(context, R.layout.open_hours_item, objOpenHours);
		this.context = context;
		this.objOpenHours = objOpenHours;
	}

	@Override
	public ObjOpenHours getItem(int position) {
		return objOpenHours.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public int getCount() {
		return 7;
	}

	@Override
	public View getView(int position, View v, ViewGroup parent) {
		Holder holder = null;
		if (v == null) {
			LayoutInflater inflater = LayoutInflater.from(getContext());
			v = inflater.inflate(R.layout.open_hours_item, parent, false);
			holder = new Holder();

			holder.txtThoigian = (TextView) v.findViewById(R.id.txt_thungay);
			holder.txtThungay = (TextView) v.findViewById(R.id.txt_thoigian);

			v.setTag(holder);
		} else {
			holder = (Holder) v.getTag();
		}

		ObjOpenHours objOpenHour = objOpenHours.get(position);

		holder.txtThungay.setText(objOpenHours.get(position).getThoigianMocua()
				.toUpperCase());

		holder.txtThoigian.setText(IOUtils.toOnlyFirstUpcase(objOpenHours.get(
				position).getThuNgay()));
		return v;
	}

	class Holder {
		TextView txtThoigian;
		TextView txtThungay;
	}

}
